package com.renu.jdependencyanalyser.visualizer;

import com.renu.jdependencyanalyser.freemarker.AbstractProcessor;
import freemarker.template.TemplateException;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;

import java.io.FileOutputStream;
import java.io.IOException;

public class PlantUMLVisualizer implements Visualizer{
    @Override
    public void generateGraph(AbstractProcessor processor, String fileName) {
        try {
            String code = processor.process();
            SourceStringReader reader = new SourceStringReader(code);
            reader.generateImage(new FileOutputStream(fileName), new FileFormatOption(FileFormat.PNG));

            System.out.println("UML diagram generated successfully!");
        } catch (TemplateException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

}
